package com.qinyeit.codegen.entity;

import com.qinyeit.codegen.GenUtils;

public class Column {

	private String columnName = "";

	private String columnType = "";

	private int columnLength = 255;

	private String columnComment = "";

	private boolean notNull = false;

	private String defaultValue = "";
	private String columnDesc = "";

	public Column(String columnName, String columnType, int columnLength, String columnComment, String columnDesc){
		this.columnName = columnName;
		this.columnType = columnType;
		this.columnLength = columnLength;
		this.columnComment = columnComment;
		this.columnDesc = columnDesc;
	}

	public String getColumnDesc() {
		return columnDesc;
	}

	public void setColumnDesc(String columnDesc) {
		this.columnDesc = columnDesc;
	}

	public String getColumnName() {
		return columnName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	public String getColumnType() {
		return columnType.toUpperCase();
	}

	public void setColumnType(String columnType) {
		this.columnType = columnType;
	}

	public String getColumnComment() {
		return columnComment;
	}

	public void setColumnComment(String columnComment) {
		this.columnComment = columnComment;
	}

	public int getColumnLength() {
		return columnLength;
	}

	public void setColumnLength(int columnLength) {
		this.columnLength = columnLength;
	}

	public boolean isNotNull() {
		return notNull;
	}

	public String getDateType(){
		if(columnType.toLowerCase().contains("date")){
			return columnType.toLowerCase();
		}
		return null;
	}

	public String getDataType(){
		return columnType.toLowerCase();

	}

	public void setNotNull(boolean notNull) {
		this.notNull = notNull;
	}

	public String getDefaultValue() {
		return "null";
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	//获取驼峰命名
	public String getHumpName(){
		return GenUtils.hump(columnName);
	}
	public String getUpperHumpName(){
		return GenUtils.toCaseOne(getHumpName(), true);
	}


	//获取java 类型
	public String getFieldType(){
		String rv ;
		switch (ColumnType.valueOf(columnType.toUpperCase())) {
		case BIGINT:
			rv = "Long";
			break;
		case SMALLINT:
		case TINYINT:
		case INT:
			rv = "Integer";
			break;
		case FLOAT:
			rv = "Float";
			break;
		case DECIMAL:
		case DOUBLE:
			rv = "Double";
			break;
		case BIT:
		case BOOL:
		case BOOLEAN:
			rv = "Boolean";
			break;
		case CHAR:
		case VARCHAR:
		case TEXT:
		case MEDIUMTEXT:
			rv = "String";
			break;
		case DATE:
		case DATETIME:
			rv = "Date";
			break;
		default:
			rv = "String";
			break;
		}
		return rv;
	}
}
